package java9_22.Test2;

import java.io.*;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class User1 extends Thread {
private Socket s;

    public User1(Socket s) {
        this.s = s;
    }

    @Override
    public void run() {
        HashMap<String, Integer> m = new HashMap<>();
        m.put("赵鹏程", 1001);
        m.put("吴浩林", 1002);
        m.put("林超", 1003);
        Set<Map.Entry<String, Integer>> e1 = m.entrySet();
        try {
            OutputStream o = s.getOutputStream();
            InputStream i = s.getInputStream();

            PrintWriter p = new PrintWriter(o,true);
            ObjectInputStream o1 = new ObjectInputStream(i);
            while (m.isEmpty() == false) {
                p.println("请输入用户名和密码");
                User o2 = (User) o1.readObject();
                boolean b = false;
                for (Map.Entry<String, Integer> s2 : e1) {
                    if (o2.getName().equals(s2.getKey()) && s2.getValue().equals(o2.getCipher())) {
                        b = true;
                        p.println("登陆成功");
                    }
                }
                if (b = false)
                    p.println("登录失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                s.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

